/**
* 可以对任意输入的年月日，求出对应星期几
* @author yangjian 2009-3-28
* */
package GetWeek;

import java.util.Scanner;

public class GetWeek {

	/**
	 * @param year
	 * @return boolean
	 * 判断是否为闰年
	 * */
	public static boolean isLeapYear(int year) {
		if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
			return true;		         		    
		} else {
			return false;
		}
	}
	/**
	 * @param year,month
	 * @return int
	 * 返回月中的天数
	 * */
	public static int getDayOfMonth(int year,int month)
	{
		switch(month)
		{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			return 31;
		case 4:
		case 6:
		case 9:
		case 11:
			return 30;
		case 2:
			if (isLeapYear(year)) {
				return 29;
			} else {
				return 28;
			}
		default:
			return 0;
		}
	}
	/**
	 * @param year
	 * @return int
	 * 返回一年中有多少天
	 * */
	public static int getDayOfYear(int year) {
		int days=0;
		if (isLeapYear(year)) {
			days = 366;
		} 
		else {
			days = 365;
		}
		return days;
	}
	/**
	 * @param week
	 * @return String
	 * 返回星期几
	 * */
	public static String getWeekDay(int week){
    	switch (week) {
    	//因为基准为1980年1月1日,为星期二,相除为0则为星期二
    	case 0 :return "星期二";
    	case 1 :return "星期三";
    	case 2 :return "星期四";
    	case 3 :return "星期五";
    	case 4 :return "星期六";
    	case 5 :return "星期日";
    	case 6 :return "星期一";
    	default: return "";
    	}
	}
	/**
	 * @param year
	 * @return int
	 * 距离现在年份的总数,基准为1980年1月1日,为星期二
	 * */
	public static int dayOfDistanceYear(int year)
	{
		int days=0;
		//当前年份不算在内,距离1980年,一共过了多少年,并计算天数
		for(int i=1980;i<year;i++)
		{
			days+=getDayOfYear(i);
		}
		return days;
	}
	/**
	 * @param year,month
	 * @return int
	 * 现在年份的所有月份中的天数
	 * */
	public static int dayOfCurrentYear(int year,int month)
	{
		int days=0;
		//当前年份所有月份中的天数
		for(int i=1;i<month;i++)
		{
			days+=getDayOfMonth(year,i);
		}
		return days;
	}
	public static int inputYear()
	{
		int year;
		Scanner scan=new Scanner(System.in);
		System.out.print("请输入年份:");
		year=scan.nextInt();
		while(year<1980 || year>2099)
		{
			System.out.print("输入错误,请重新输入:");
			year=scan.nextInt();
		}
		return year;
	}
	public static int inputMonth()
	{
		int month;
		Scanner scan=new Scanner(System.in);
		System.out.print("请输入月份:");
		month=scan.nextInt();
		while(month < 0 || month > 12)
		{
			System.out.print("输入错误,请重新输入:");
			month=scan.nextInt();
		}
		return month;
	}
	public static int inputDays()
	{
		int days;
		Scanner scan=new Scanner(System.in);
		System.out.print("请输入日:");
		days=scan.nextInt();
		while(days < 1 || days > 31)
		{
			System.out.print("输入错误,请重新输入:");
			days=scan.nextInt();
		}
		return days;
	}
	public static String days(int year,int month,int day)
	{
		String week="";
		int days=0;
		days=dayOfDistanceYear(year)+dayOfCurrentYear(year,month)+day-1;
		week=getWeekDay(days%7);
		return week;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int year,month,day; 
		
		//int days=0;
		year=inputYear();
		month=inputMonth();
		day=inputDays();
		System.out.println("你输入的日期: "+year+"年"+month+"月"+day+"日");
		//days=dayOfDistanceYear(year)+ dayOfCurrentYear(year,month)+day-1;
		System.out.println(days(year,month,day));
	}

}
